import unittest
import uuid

from Autotests.BaseTest import BaseManservSOAPTestCase


class Location(BaseManservSOAPTestCase):
    def __init__(self, *args, **kwargs):
        super(Location, self).__init__(*args, **kwargs)

    def setUp(self, *args, **kwargs):
        super(Location, self).setUp(*args, **kwargs)

    def test_Locations(self):
        count = self._getLocationCount()
        locationName = str(uuid.uuid4())
        #AddLocation
        addLocationResult = self.manserv.AddLocation(id = '1', name = locationName)
        self.assertTrue(addLocationResult.isnumeric())
        countAfter = self._getLocationCount()
        self.assertEqual(count + 1, countAfter)

        #EnumerateLocations
        enumerateLocationResult = self.manserv.EnumerateLocations()
        self.assertEqual(enumerateLocationResult.locationInfo[-1].id, addLocationResult)
        self.assertEqual(enumerateLocationResult.locationInfo[-1].name, locationName)

        #GetLocationInfoByName
        with self.assertRaises(Exception) as exc:
            self.manserv.GetLocationInfoByName(name = locationName)
        self.assertEqual(exc.exception.message, (502, u'Bad Gateway'))

#---
    def _getLocationCount(self):
        result = self.manserv.EnumerateLocations()
        return len(result.locationInfo)


if __name__ == "__main__":
    unittest.main()

